package org.mindrive.system.config;

import java.lang.reflect.Type;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.StringCodec;

public class StringTrimDeserializer implements ObjectDeserializer {

	@Override
	public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
		Object obj = StringCodec.instance.deserialze(parser, type, fieldName);
		if (obj instanceof String && obj != null) {
			String str = (String) obj;
			System.out.println(">>>>>>>" + fieldName + ":" + str);
			return (T) str.trim();
		}
		return (T) obj;
	}

	@Override
	public int getFastMatchToken() {
		return JSONToken.LITERAL_STRING;
	}

}
